/*
pthread_spin_init()
pthread_spin_lock()
pthread_spin_unlock()
pthread_spin_destroy()
*/


#include <pthread.h>
#include <iostream>

using namespace std;


pthread_spinlock_t spinlock;
int counter = 0;

void* increment(void* arg)
{
	pthread_spin_lock(&spinlock);
	counter++;
	pthread_spin_unlock(&spinlock);

	return nullptr;
}


int main(int argc,char** argv)
{
	pthread_t t1,t2;
	
	pthread_spin_init(&spinlock,0);

	pthread_create(&t1,nullptr,increment,nullptr);
	pthread_create(&t2,nullptr,increment,nullptr);

	pthread_join(t1,nullptr);
	pthread_join(t2,nullptr);
	

	cout << "counter:" << counter << endl;

	pthread_spin_destroy(&spinlock);

	return 0;
}














